package var.syntax;

import tr.edu.ege.kipler.syntax.ModalOperator;
import tr.edu.ege.kipler.syntax.TypedModality;

public class MOperator extends ModalOperator implements TypedModality {

	private static final String BOX = "[M]";

	private static final String DIAMOND = "<M>";

	public static MOperator box() {
		MOperator op = new MOperator();
		op.setModality(BOX);
		return op;
	}

	public static MOperator diamond() {
		MOperator op = new MOperator();
		op.setModality(DIAMOND);
		return op;
	}

	private String getModality() {
		return (String) getParameter("modality");
	}

	private void setModality(String modality) {
		setParameter("modality", modality);
	}

	public ModalOperator getDual() {
		ModalOperator result;
		if (getModality() == BOX) {
			result = diamond();
		} else {
			result = box();
		}
		return result;
	}

	public ModalOperator copy() {
		MOperator result = new MOperator();
		result.setModality(getModality());
		return result;
	}

	public boolean isNecessiate() {
		return getModality().equals(BOX);
	}

	public String getType() {
		return "monotonic";
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuffer buffer = new StringBuffer();
		char var;
		if (isNecessiate()) {
			var = '[';
		} else {
			var = '<';
		}
		buffer.append(var);
		buffer.append("M");
		if (isNecessiate()) {
			var = ']';
		} else {
			var = '>';
		}
		buffer.append(var);
		return buffer.toString();
	}

}
